package js.dwim.domain;

import java.util.HashMap;
import java.util.Map;

public class Command
{
    public enum Type
    {
        Unknown,
        Help,
        PlayerInfo,
        PlayerChangeName,
        DebugWipeAll,
        CloseSession,
        GetServerTime,
        GameStats,
        Scoreboard,
        GameRequest,
    }

    public static final Map<Type, String> KEYWORDS = new HashMap<Command.Type, String>()
    {
        private static final long serialVersionUID = 1L;
        {
            put( Type.Help,             "/help" );
            put( Type.PlayerInfo,       "/me" );
            put( Type.PlayerChangeName, "/name" );
            put( Type.DebugWipeAll,     "/wipe" );
            put( Type.CloseSession,     "/quit" );
            put( Type.GetServerTime,    "/time" );
            put( Type.GameStats,        "/stats" );
            put( Type.Scoreboard,       "/score" );
            put( Type.GameRequest,      "/play" );
        }
    };

    private Type type;

    private String args;

    public Command( String cmd )
    {
        for ( Type t : Type.values() )
        {
            if ( t == Type.Unknown )
                continue;

            String val = KEYWORDS.get( t );
            if ( cmd.startsWith( val ) )
            {
                this.type = t;
                this.args = cmd.substring( val.length() );
                return;
            }
        }
        this.type = Type.Unknown;
        this.args = cmd;
    }

    public Type getType()
    {
        return type;
    }

    public String getArgs()
    {
        return args;
    }
}
